clear all
set more off

*** Programs 
cap program drop _all
*------------------------------------------------------------------------------
program define sumstats_row1
preserve
gen var = "`1'"
collapse (count) Obs = `1' (mean) mean = `1' (sd) sd = `1' [aw=peso] if time>tq(2012q2) , by(var)
save "\outregsQJE\Appendix_Summary_Stats.dta",  replace
restore
end 
*------------------------------------------------------------------------------
program define sumstats
preserve
gen var = "`1'"
collapse (count) Obs = `1' (mean) mean = `1' (sd) sd = `1' [aw=peso] if time>tq(2012q2) , by(var)
append using "\outregsQJE\Appendix_Summary_Stats.dta"
save         "\outregsQJE\Appendix_Summary_Stats.dta",  replace
restore 
end


local out2="\outregsQJE\"
cd         "\workfiles"

use step001_QJE, clear
format time %tq

*** 3-month ahead: mean and std
gen mean3m=( (-1)*sitm3m + 0*situ3m + 1*sitp3m )/100
gen uncertainty3m=( (-1-mean3m)^2*sitm3m + (0-mean3m)^2*situ3m + (1-mean3m)^2*sitp3m )/100
replace uncertainty3m=uncertainty3m^0.5

*** 3-year ahead: mean and std
gen mean3a=( (-1)*sitm3a + 0*situ3a + 1*sitp3a )/100
gen uncertainty3a=( (-1-mean3a)^2*sitm3a + (0-mean3a)^2*situ3a + (1-mean3a)^2*sitp3a )/100
replace uncertainty3a=uncertainty3a^0.5

*** construct continuous measure of export
gen export4R=(1+2/3)/2  		if export4==1
replace export4R=(1/3+2/3)/2  	if export4==2
replace export4R=(1/3+0)/2  	if export4==3
replace export4R=0			  	if export4==4
*-------------------------------------------------------------------------------
gen promigR=0 if promig==1
replace promigR=12.5 if promig==2
replace promigR=37.5 if promig==3
replace promigR=62.5 if promig==4
replace promigR=88.5 if promig==5
replace promigR=100  if promig==6
*------------------------------------------------------------------------------
gen sitgenR=sitgen-2
gen sitimp5R=sitimp5-3
gen sitcreR=sitcre-2
gen pretotR=pretot-2
gen liquidR=liquid-2
gen occtotR=occtot-2
gen invpreR=invpre-3
*-------------------------------------------------------------------------------



sumstats_row1 add_new
sumstats prpr 
sumstats clpr
sumstats mppr  
sumstats dpr
sumstats dprez
sumstats uncertainty3m
sumstats uncertainty3a
sumstats invpreR
sumstats sitimp5R
sumstats liquidR
sumstats occtotR
sumstats pretotR
sumstats promigR
sumstats sitgenR
sumstats sitcreR
sumstats dpre
sumstats it48n
sumstats it24n
sumstats it12n
sumstats it6n
sumstats it48
sumstats it24
sumstats it12
sumstats it6
sumstats export4R  
sumstats add

use  "\outregsQJE\Appendix_Summary_Stats.dta", clear

export delimited using "\outregsQJE\Appendix_Summary_Stats.csv", replace

